/*
ont-space - The ontology-based resource metadata repository
Copyright (c) 2006-2008, Information Eng. Research Unit - Univ. of Alcalá
http://www.cc.uah.es/ie
This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option)
any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License along
with this library; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
package org.ontspace.util.translator.sld2owl.owl;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.hp.hpl.jena.ontology.OntModel;
import java.io.*;

/**
 *This class translate the xml file and store the ontology when it is translated
 *
 */
public class SLDXML2OWLConversion {

    OntModel ont;
    String nsName =
            "http://www.cc.uah.es/ie/ont/sld-ospace#";

    /** Creates a new instance of SLDXML2OWLConversion */
    /**
     * Creates a new instance of SLDXML2OWLConversion. 
     * @param doc the document node
     * @param ont The ontology
     * @param nsName The namespace
     * @param outputFile The output ontology file
     */
    public SLDXML2OWLConversion(Node doc, OntModel ont, String nsName,
            OutputStream outputFile) {


        try {
            readTree(doc, ont, nsName);

        } catch (Exception ex) {
            ex.printStackTrace();
        }



    }

    /**
     * Read DOM Tree.If the element readed is a node,
     * it calls the class of the node type 
     *     The classes which can be called are:
     *      LearningDesignTranslator
     *      DomLearningObjectives
     *      DomPrerequisites
     *      DomComponents
     *      DomMethod
     */
    private void readTree(Node node, OntModel ont, String nsName) {

        if (node.getNodeName().compareTo("imsld:learning-design") == 0) {
            LearningDesignTranslator dln =
                    new LearningDesignTranslator(node, ont, nsName);
        }
        if (node.getNodeName().compareTo("resources") == 0) {
            ResourcesTranslator dr =
                    new ResourcesTranslator(node, ont, nsName);
        }


        NodeList children =
                node.getChildNodes();
        if (children != null) {
            for (int i =
                    0; i < children.getLength(); i++) {
                readTree(children.item(i), ont, nsName);
            }
        }
    }

    /**
     *Print the ontology and strore it in a owl file
     */
    public void storeOntology(OntModel ont, OutputStream ontologyFile) {
        try {
            ont.write(ontologyFile);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }
}
